﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BG.DAL.Model;
using BG.DAL.Context;
using System.Data;

namespace BG.DAL.SQLDAL
{
    public class TicketManager
    {
        public static Ticket GetById(Guid id)
        {
            using (DataContext db = new DataContext())
            {
                Ticket Model = db.Tickets.Find(id);
                return Model;
            }
        }

        public static List<Ticket> GetAll()
        {
            using (DataContext db = new DataContext())
            {
                var i = db.Tickets.ToList();
                return i;
            }
        }

        public static List<Ticket> GetByFilter(string text)
        {
            using (DataContext db = new DataContext())
            {
                return db.Tickets.Where(m => m.sTicketNumber.Equals(text)).ToList();
            }
        }

        public static void Create(Ticket model)
        {
            using (DataContext db = new DataContext())
            {
                db.Tickets.Add(model);
                db.SaveChanges();
            }
        }

        public static void Edit(Ticket model)
        {
            using (DataContext db = new DataContext())
            {
                db.Entry(model).State = EntityState.Modified;
                db.SaveChanges();
            }
        }

        public static void Delete(Guid id)
        {
            using (DataContext db = new DataContext())
            {
                Ticket model = db.Tickets.Find(id);
                db.Tickets.Remove(model);
                db.SaveChanges();

            }
        }
    }
}
